<template>
  <div class="evaluate-box">
    <!--侍酒师评价-->
    <div class="message" v-if="showSommelier">
      <div class="avatar-box">
        <img :src="source+sommelierInfo.imageUrl" alt="">
        <span>{{sommelierInfo.name}}</span> <span class="role">侍酒师</span>
      </div>
      <div class="fl-box">
        <!--<div class="fb-left">-->
          <!--预约时间：2018-07-20 10：55-->
        <!--</div>-->
        <!--<div class="fb-right">人数：33人</div>-->
      </div>
      <div class="fl-c">
        <div class="fc-left">
          <div class="img-box" :class="{on:isGood}" @click="isGood=!isGood">
            <img v-if="!isGood" src="../../assets/images/satisfaction.png" alt="">
            <img v-else="!isGood" src="../../assets/images/satisfaction_on.png" alt="">
            <span>好评</span>
          </div>
        </div>
        <div class="fc-right">
          <div class="img-box" :class="{on:isMid}" @click="isMid=!isMid">
            <img v-if="!isMid" src="../../assets/images/satisfaction.png" alt="">
            <img v-else="isMid" src="../../assets/images/satisfaction_on.png" alt="">
            <span>中评</span>
          </div>
        </div>
        <div class="fc-left">
          <div class="img-box" :class="{on:isBad}" @click="isBad=!isBad">
            <img v-if="!isBad" src="../../assets/images/discontent.png" alt="">
            <img v-else="!isBad" src="../../assets/images/discontent_on.png" alt="">
            <span>差评</span>
          </div>
        </div>
      </div>

      <!--评价标签项-->
      <!--<ul class="ul-flex">-->
        <!--<li :key="index" v-for="(item,index) in tags1" @click="item.status=!item.status"><span-->
          <!--:style="{background:(item.status?libg[Math.floor(Math.random()*10)]:'')}"-->
          <!--:class="{select:item.status}">{{item.label}}</span></li>-->
        <!--<li><span>＋</span></li>-->
      <!--</ul>-->
      <textarea maxlength="80" placeholder="添加备注80字以内" v-model="remarks1"></textarea>
    </div>
    <!--酒产品评价-->
    <div class="message">
      <div class="m-flex" v-for="(item,index) in goods">
        <div class="mf-left">
          <img :src="source+item.goods.goodsImg" alt="">
        </div>
        <div class="mf-right">
          <p>{{item.goods.goodsName}}</p>
          <!--<div>黑加仑樱桃等新鲜水果香气精致的单宁加上木桶的醇香让 人回…… </div>-->
        </div>
      </div>
      <!--评价标签项-->
      <!--<ul class="ul-flex">-->
        <!--<li :key="index" v-for="(item,index) in tags2" @click="item.status=!item.status"><span-->
          <!--:style="{background:(item.status?libg[Math.floor(Math.random()*10)]:'')}"-->
          <!--:class="{select:item.status}">{{item.label}}</span></li>-->
        <!--&lt;!&ndash;<li><span>＋</span></li>&ndash;&gt;-->
      <!--</ul>-->
      <textarea maxlength="80" placeholder="添加备注80字以内" v-model="remarks2"></textarea>
    </div>
    <div class="btn" @click="submitbtn()">
      <button>提交</button>
    </div>
  </div>
</template>

<script>
  import global from '../public/global.vue'

  export default {
    name: 'evaluate',
    data() {
      return {
        isCur: true,//是否满意
//        tags:['服务态度好','专业知识丰富','长的帅','个子高','名字好听','小猪头肉'],//标签项
        tags1: [
//          {status: false, describ: "服务态度好"},
//          {status: false, describ: "专业知识丰富"},
//          {status: false, describ: "长的帅"},
//          {status: false, describ: "个子高"},
//          {status: false, describ: "名字好听"},
//          {status: false, describ: "小猪头肉"},
        ],//侍酒师标签项
        tags2: [
//          {status: false, describ: "性价比高"},
//          {status: false, describ: "口感优良醇正"},
//          {status: false, describ: "很好喝"},
        ],//侍酒师标签项
        libg: global.libg,
        remarks1: '', //侍酒师备注内容
        remarks2: '', //产品备注内容
        showSommelier:false,
        sommelierInfo:{},
        goods:[],
        source:global.sourceUrl,
        isGood:true,
        isMid:false,
        isBad:false
      }
    },
    methods: {
      //提交
      submitbtn(){
        let i = 0
        let type = 1
        if(this.isGood){
          i++
          type=1
        }
        if(this.isMid){
          i++
          type=2
        }
        if(this.isBad){
          i++
          type=3
        }
        if(i>1){
          alert("只能选择一种评价")
          return;
        }
        if(i<1){
          alert("请选择一种评价")
          return;
        }
        this.goodsEvaluate();
        if(this.showSommelier){
          this.sommelierEvaluate(type);
        }
      },
      goodsEvaluate(){
        let params = new URLSearchParams();
        let billNo = this.$route.query.id
        let uid = global.getCookie("uid");
        let goodsId = this.goods[0].goods.id
        let note = this.remarks2
        params.append("billNo",billNo)
        params.append("uid",uid)
        params.append("goodsId",goodsId)
        params.append("note",note)
        console.log(billNo)
        console.log(uid)
        console.log(goodsId)
        console.log(note)
        this.$http({
          method: "post",
          url: global.apiUrl + '/order/evaluate',
          data: params,
        }).then(res => {
          if (res.data.code == 0) {
            this.$router.go(-1)
          }
        }).catch(function (err) {
          console.error(err);
        })
      },
      sommelierEvaluate(type){
        let params = new URLSearchParams();
        let billNo = this.$route.query.id
        let uid = global.getCookie("uid");
        let note = this.remarks1
        let agentId = this.sommelierInfo.uid
        params.append("billNo",billNo)
        params.append("uid",uid)
        params.append("note",note)
        params.append("agentId",agentId)
        params.append("score",type)
        this.$http({
          method: "post",
          url: global.apiUrl + '/sommelier/evaluate',
          data: params,
        }).then(res => {
          if (res.data.code == 0) {

          }
        }).catch(function (err) {
          console.error(err);
        })
      }
    },
    created: function () {
      document.title = "评价订单"
      let billNo = this.$route.query.id
      console.log(billNo)
      let url = global.apiUrl;
      //侍酒师标签
      this.$http.get(url + "/label/getLabels", {
        params: {type: 0}
      }).then(res => {
        console.log(res.data);
        if (res.data.code == 0) {
          this.tags1 = res.data.data;
        }
      }).catch(function (err) {
        console.error("Error:" + err);
      })
      //商品标签
      this.$http.get(url + "/label/getLabels", {
        params: {type: 2}
      }).then(res => {
        console.log(res.data);
        if (res.data.code == 0) {
          this.tags2 = res.data.data;
        }
      }).catch(function (err) {
        console.error("Error:" + err);
      })
      //侍酒师信息
      this.$http.get(url + '/order/getSommelierByOrder', {
        params: {
          billNo: billNo,
        }
      }).then(res => {
        if (res.data.code == 0) {
          console.log(res.data.data);
          if(res.data.data.level==3){
            this.showSommelier = true
            this.sommelierInfo = res.data.data
          }
        }
      }).catch(function (err) {
        console.error(err);
      })
      this.$http.get(url + '/order/orderDetail', {
        params: {
          billNo: billNo,
        }
      }).then(res => {
        if (res.data.code == 0) {
          console.log(res.data.data);
          this.goods = res.data.data.orderGoodsList
          console.log(this.goods)
        }
      }).catch(function (err) {
        console.error(err);
      })
    },
    mounted: function () {

    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
  .evaluate-box {
    position: absolute;
    top: 0;
    width: 100%;
    min-height: 100%;
    background: #f3f3f3;
    .message {
      width: 100%;
      padding: 2% 2.5%;
      background: #fff;
      margin-bottom: 10px;
      font-size: 1rem;
      color: #333;
    }
    .avatar-box {
      width: 100%;
      padding: 10px 0;
      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        vertical-align: middle;
      }
      .role {
        font-size: 0.85rem;
        color: #fff;
        padding: 0px 10px;
        background: #FB3C3D;
        border-radius: 30px;
      }
    }
    .fl-box {
      width: 100%;
      padding-bottom: 10px;
      display: flex;
      justify-content: space-between;
      font-size: 0.9rem;
    }
    .fl-c {
      width: 100%;
      text-align: center;
      display: flex;
      .fc-left {
        flex: 1;
      }
      .fc-right {
        flex: 1;
      }
      .img-box {
        width: 70%;
        margin: 5px auto 10px;
        border: 1px solid #aaa;
        font-size: 0.9rem;
        color: #666;
        padding: 5px 0;
        border-radius: 40px;
        img {
          width: 24px;
          vertical-align: middle;
        }
      }
      .on {
        border-color: #d44242;
        background: #d44242;
        color: #fff;
      }
    }
    /*标签选项*/
    .ul-flex {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        span {
          font-size: 0.85rem;
          color: #666;
          padding: 4px 10px;
          border: 1px solid #aaa;
          border-radius: 30px;
        }
        .select {
          border-color: transparent;
          color: #fff;
        }
      }
    }
    /*textarea添加备注*/
    textarea {
      -webkit-appearance: none;
      width: 100%;
      padding: 2px 5px;
      box-sizing: border-box;
      min-height: 4rem;
      font-size: 0.9rem;
      resize: none;
      border-radius: 4px;
      border-color: #aaa;
      margin-bottom: 10px;
    }
    /*产品评价部分*/
    .m-flex {
      width: 100%;
      padding: 2% 0;
      margin-bottom: 10px;
      display: flex;
      border-bottom: 1px solid #eee;
      .mf-left {
        flex: 2;
        img {
          width: 50px;
          height: 50px;
          border-radius: 50%;
        }
      }
      .mf-right {
        flex: 10;
        p {
          width: 100%;
          overflow: hidden;
          -ms-text-overflow: ellipsis;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        div {
          font-size: 0.8rem;
          color: #aaa;
        }
      }
    }
    /*提交*/
    .btn {
      width: 100%;
      padding:2% 2.5%;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      button{
        -webkit-appearance: none;
        width:100%;
        height:3rem;
        line-height: 3rem;
        margin: 0 auto;
        padding: 0;
        border: none;
        background: #D43F3F;
        border-radius:6px;
        font-size: 1rem;
        color:#fff;
      }
    }
  }
</style>
